//
//  TeamDriverAuthVC.m
//  阿帕
//
//  Created by mac on 2020/9/12.
//  Copyright © 2020 GCY. All rights reserved.
//

#import "CarTeamAuthVC.h"
#import "ImageUploadViewController.h"
#import "TZImagePickerController.h"
#import "GeneralPopUp.h"
#import "CYCityChooseView.h"

//人脸识别
#ifdef isOpenBaiDuFaceSDK
#import "BDFaceLivenessViewController.h"
#import "BDFaceDetectionViewController.h"
#import "BDFaceLivingConfigModel.h"
#import "IDLFaceSDK/IDLFaceSDK.h"
#import "FaceParameterConfig.h"
#endif

@interface CarTeamAuthVC ()<DeliveredImageUrlDelegate, CYChooseRegionDelegate, UITextFieldDelegate>
{
    
    NSString *_identificationImg;
    NSString *_identificationBackImg;
    NSString *_businessLicenseImg;
    NSString *_roadPermitNumberImg;
    NSString *_safeDutyInsureImg;
    NSString *_sex;//性别
    NSString *_allowDriverReceive; // 是否允许司机抢单
    
    NSString *_provinceCode;
    NSString *_cityCode;
    NSString *_countyCode;
    NSString *_lastIdardDueDate;//记录上一次选择身份证到期的日期

    BOOL _isClearing;//是否清分
    
    BOOL _idCardIsLongtime;//身份证是否是长期
    
}

@property (strong , nonatomic)ImageUploadViewController *uploadImgVC;

@property (strong , nonatomic)UIView *photoBgView;

@property (strong , nonatomic)UILabel *identificationBtn;
@property (strong , nonatomic)UILabel *identificationBackBtn;
@property (strong , nonatomic)UILabel *businessLicenseImgBtn;
@property (strong , nonatomic)UILabel *roadPermitNumberImgBtn;
@property (strong , nonatomic)UILabel *safeDutyInsureImgBtn;
@property (strong , nonatomic)UILabel *dlysjyxkeAsterisk;
@property (strong , nonatomic)UILabel *dlysjyxkeImgAsterisk;
@property (strong , nonatomic)UILabel *authStateLabel;
@property (strong , nonatomic)UILabel *authStateDetailLabel;

@property (strong , nonatomic)UITextField *cheDuiMingChengTF;
@property (strong , nonatomic)UITextField *phoneTF;
@property (strong , nonatomic)UITextField *lianXiRenTF;
@property (strong , nonatomic)UITextField *tongXunDiZhiTF;
@property (strong , nonatomic)UITextField *detailAddressTF;
@property (strong , nonatomic)UITextField *sheHuiTongYiXinYongDaiMaTF;
@property (strong , nonatomic)UITextField *faRenTF;
@property (strong , nonatomic)UITextField *idCardNumTF;
@property (strong , nonatomic)UITextField *daoLuYunShuJingYingXuKeZhengTF;
@property (strong , nonatomic)UITextField *gongZuoDanWeiTF;
@property (strong , nonatomic)UITextField *beiZhuTF;
@property (strong , nonatomic)UITextField *cleanRatioTF;
@property (strong , nonatomic)UITextField *idCardDueDateTF;

@property (strong , nonatomic)UIImageView *notAllowDriverReceivView;
@property (strong , nonatomic)UIImageView *allowDriverReceivImageView;
@property (strong , nonatomic)UIImageView *manImageView;
@property (strong , nonatomic)UIImageView *womenImageView;
@property (strong , nonatomic)UIImageView *authTopImageView;
@property (strong , nonatomic)UIImageView *clearingImageView;
@property (strong , nonatomic)UIImageView *idCardDateIsLongtimeImageView;

@property (strong , nonatomic)UIButton *saveBtn;

@property (strong , nonatomic)UILabel *identificationBtnView;
@property (strong , nonatomic)UILabel *identificationBackBtnView;
@property (strong , nonatomic)UILabel *businessLicenseImgBtnView;
@property (strong , nonatomic)UILabel *safeDutyInsureImgBtnView;
@property (strong , nonatomic)UILabel *linkManView;
@property (strong , nonatomic)UILabel *phoneTFView;
@property (strong , nonatomic)UILabel *lianXiRenTFView;
@property (strong , nonatomic)UILabel *tongXunDiZhiTFView;
@property (strong , nonatomic)UILabel *detailAddressTFView;
@property (strong , nonatomic)UILabel *sheHuiTongYiXinYongDaiMaTFView;
@property (strong , nonatomic)UILabel *faRenTFView;
@property (strong , nonatomic)UILabel *idCardNumTFView;
@property (strong , nonatomic)UILabel *gongZuoDanWeiTFView;
@property (strong , nonatomic)UILabel *sexView;
@property (strong , nonatomic)UILabel *idCardDueDateRemindLabel;///身份证到期提醒文字
@property (strong , nonatomic)UILabel *idCardDueDateView;///身份证有效期必填星号

@property (strong , nonatomic)NSDictionary *dynamicFieldDic;

/** 容器View */

/// 身份证正面照
@property (strong , nonatomic)UIView *identificationImgContainerView;
/// 身份证背面照
@property (strong , nonatomic)UIView *identificationBackImgContainerView;
/// 统一社会信用代码照片
@property (strong , nonatomic)UIView *businessLicenseImgContainerView;
/// 道路运输经营许可证照
@property (strong , nonatomic)UIView *roadPermitNumberImgContainerView;
/// 安全责任险照
@property (strong , nonatomic)UIView *safeDutyInsureImgContainerView;
/// 车队名称
@property (strong , nonatomic)UIView *linkManContainerView;
/// 联系电话
@property (strong , nonatomic)UIView *phoneContainerView;
/// 联系人
@property (strong , nonatomic)UIView *nameContainerView;
/// 通讯地址
@property (strong , nonatomic)UIView *areaListContainerView;
/// 详细地址
@property (strong , nonatomic)UIView *homeAddressContainerView;
/// 统一社会信用代码
@property (strong , nonatomic)UIView *businessLicenseNumberContainerView;
/// 道路运输经营许可证号
@property (strong , nonatomic)UIView *roadPermitNumberContainerView;
/// 法人代表
@property (strong , nonatomic)UIView *legalPersonContainerView;
/// 身份证号
@property (strong , nonatomic)UIView *identificationNumberContainerView;
/// 身份证有效期
@property (strong , nonatomic)UIView *idCardDueDateContainerView;
/// 工作单位
@property (strong , nonatomic)UIView *workCompanyContainerView;
/// 性别
@property (strong , nonatomic)UIView *sexContainerView;
/// 备注
@property (strong , nonatomic)UIView *remarkContainerView;
/// 是否允许司机抢单
@property (strong , nonatomic)UIView *allowDriverReceiveView;
/// 是否清分
@property (strong , nonatomic)UIView *isShareContainerView;
/// 清分比率
@property (strong , nonatomic)UIView *cleanRatioView;


@end

@implementation CarTeamAuthVC

- (void)dealloc {
    [KNotificationCenter removeObserver:self name:@"faceIdentifySuccess" object:nil];
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.navigationItem.title = @"车队认证信息";
    
    [self baseSetup];
    
    [self formValidationSetup];
    
    [self getAuthDetailInfoRequest];
    
    [self fieldCalibrationRequest];///动态字段配置
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
}

- (void)baseSetup {
    
    [KNotificationCenter addObserver:self selector:@selector(faceIdentifyCompleted:) name:@"faceIdentifySuccess" object:nil];

    _sex = @"";
    _allowDriverReceive = @"";
    _provinceCode = @"";
    _cityCode = @"";
    _countyCode = @"";
    _identificationImg = @"";
    _identificationBackImg = @"";
    _businessLicenseImg = @"";
    _roadPermitNumberImg = @"";
    _safeDutyInsureImg = @"";
    _lastIdardDueDate = @"";

    _authStateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 130, ScreenW, 30)];
    _authStateLabel.textAlignment = NSTextAlignmentCenter;
    _authStateLabel.text = @"待审核";
    _authStateLabel.textColor = [UIColor whiteColor];
    _authStateLabel.font = font(17);
    [_authTopImageView addSubview:_authStateLabel];
    
    _authStateDetailLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 150, ScreenW, 30)];
    _authStateDetailLabel.textAlignment = NSTextAlignmentCenter;
    _authStateDetailLabel.textColor = [UIColor redColor];
    _authStateDetailLabel.font = font(12);
    [_authTopImageView addSubview:_authStateDetailLabel];
    
    _cleanRatioTF.delegate = self;
    
    [_saveBtn setBackgroundColor:Theme_ColorValue];
    // 联系方式不允许直接修改
    _phoneTF.enabled = NO;
    _lianXiRenTF.enabled = NO;
    _idCardNumTF.enabled = NO;
}

#pragma mark - 动态字段配置
- (void)fieldCalibrationRequest {
    
    NSDictionary *parmas = @{@"fieldFrom": @"driverTeam", @"token":[UserDefaultUtil valueForKey:USER_TOKEN],};
    [HTTPManager getNetworkRequest:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-basic-api",[ReAddressDynamic shared].baseUrl], UPDATEFIELDREQUIRED) withParameter:parmas withVC:self netName:@"字段是否必填" success:^(id response, NSString *msg) {
        
        if ([DCSpeedy isBlankDictionary:response] == NO) {
            _dynamicFieldDic = response;
        }
        
        if ([response[@"identificationImg"] integerValue] == 0 && response[@"identificationImg"] != NULL) {
//            _identificationBtnView.hidden = YES;
            _identificationImgContainerView.hidden = YES;
        }
        if ([response[@"identificationBackImg"] integerValue] == 0 && response[@"identificationBackImg"] != NULL) {
//            _identificationBackBtnView.hidden = YES;
            _identificationBackImgContainerView.hidden = YES;
        }
        if ([response[@"businessLicenseImg"] integerValue] == 0 && response[@"businessLicenseImg"] != NULL) {
//            _businessLicenseImgBtnView.hidden = YES;
            _businessLicenseImgContainerView.hidden = YES;
        }
        if ([response[@"roadPermitNumberImg"] integerValue] == 0 && response[@"roadPermitNumberImg"] != NULL) {
//            _dlysjyxkeImgAsterisk.hidden = YES;
            _roadPermitNumberImgContainerView.hidden = YES;
        }
        if ([response[@"safeDutyInsureImg"] integerValue] == 0 && response[@"safeDutyInsureImg"] != NULL) {
//            _safeDutyInsureImgBtnView.hidden = YES;
            _safeDutyInsureImgContainerView.hidden = YES;
        }
        if ([response[@"linkMan"] integerValue] == 0 && response[@"linkMan"] != NULL) {
//            _linkManView.hidden = YES;
            _linkManContainerView.hidden = YES;
        }
        if ([response[@"phone"] integerValue] == 0 && response[@"phone"] != NULL) {
//            _phoneTFView.hidden = YES;
            _phoneContainerView.hidden = YES;
        }
        if ([response[@"name"] integerValue] == 0 && response[@"name"] != NULL) {
//            _lianXiRenTFView.hidden = YES;
            _nameContainerView.hidden = YES;
        }
        if ([response[@"areaList"] integerValue] == 0 && response[@"areaList"] != NULL) {
//            _tongXunDiZhiTFView.hidden = YES;
            _areaListContainerView.hidden = YES;
        }
        if ([response[@"homeAddress"] integerValue] == 0 && response[@"homeAddress"] != NULL) {
//            _detailAddressTFView.hidden = YES;
            _homeAddressContainerView.hidden = YES;
        }
        if ([response[@"businessLicenseNumber"] integerValue] == 0 && response[@"businessLicenseNumber"] != NULL) {
//            _sheHuiTongYiXinYongDaiMaTFView.hidden = YES;
            _businessLicenseNumberContainerView.hidden = YES;
        }
        if ([response[@"roadPermitNumber"] integerValue] == 0 && response[@"roadPermitNumber"] != NULL) {
//            _dlysjyxkeAsterisk.hidden = YES;
            _roadPermitNumberContainerView.hidden = YES;
        }
        if ([response[@"legalPerson"] integerValue] == 0 && response[@"legalPerson"] != NULL) {
//            _faRenTFView.hidden = YES;
            _legalPersonContainerView.hidden = YES;
        }
        if ([response[@"identificationNumber"] integerValue] == 0 && response[@"identificationNumber"] != NULL) {
//            _idCardNumTFView.hidden = YES;
            _identificationNumberContainerView.hidden = YES;
        }
        if ([response[@"workCompany"] integerValue] == 0 && response[@"workCompany"] != NULL) {
//            _gongZuoDanWeiTFView.hidden = YES;
            _workCompanyContainerView.hidden = YES;
        }
        if ([response[@"idCardDueDate"] integerValue] == 0 || response[@"idCardDueDate"] == NULL) {
//            _idCardDueDateView.hidden = YES;//身份证到期日期
            _idCardDueDateContainerView.hidden = YES;
        }
        
        if ([response[@"sex"] integerValue] == 0 || response[@"sex"] == NULL) {
            _sexContainerView.hidden = YES;
        }
        if ([response[@"remark"] integerValue] == 0 || response[@"remark"] == NULL) {
            _remarkContainerView.hidden = YES;
        }
        if ([response[@"allowDriverReceive"] integerValue] == 0 || response[@"allowDriverReceive"] == NULL) {
            _allowDriverReceiveView.hidden = YES;
        }
//        if ([response[@"isShare"] integerValue] == 0 || response[@"isShare"] == NULL) {
//            _isShareContainerView.hidden = YES;
//        }
//        if ([response[@"shareRatio"] integerValue] == 0 || response[@"shareRatio"] == NULL) {
//            _cleanRatioView.hidden = YES;
//        }
        
    } failure:^(NSInteger code, NSString *msg) {
        
    }];
}

#pragma mark - 车队认证信息获取
- (void)getAuthDetailInfoRequest {
    
    [HTTPManager getNetworkRequest:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-basic-api",[ReAddressDynamic shared].baseUrl], DRIVER_INFO) withParameter:@{@"token":[UserDefaultUtil valueForKey:USER_TOKEN],} withVC:self netName:@"车队认证信息获取" success:^(id response, NSString *msg) {
        
//        setNetImage(_avatarImage, response[@"headImg"], @"gcy_img_my_defultHead");
        // 审核状态
        NSInteger authStatus = [response[@"authStatus"] integerValue];
        _authStateLabel.text = [StatusTextJudge authStatusJudge:authStatus];
        if (authStatus == 2) {
            _authStateDetailLabel.text = [@"驳回原因:" stringByAppendingString:[NSString nullToString:CJStringWithFormat(@"%@", response[@"authMsg"])]];
            [_authTopImageView setImage:[UIImage imageNamed:@"gcy_img_ban_bg"]];
            _authStateLabel.textColor = [UIColor redColor];
        }
        
        //性别
//        _sex = [NSString nullToString:CJStringWithFormat(@"%@", response[@"sex"])];
//
//        if ([_sex isEqual:@"1"]) {
//            _manImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
//        } else if ([_sex isEqual:@"2"]){
//            _womenImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
//        }
        
        // 允许司机抢单：0允许，1禁止
        _allowDriverReceive = [NSString nullToString:CJStringWithFormat(@"%@", response[@"allowDriverReceive"])];
        if ([_allowDriverReceive isEqualToString:@"0"]) {
            _allowDriverReceivImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
        } else if ([_allowDriverReceive isEqualToString:@"1"]){
            _notAllowDriverReceivView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
        }
        
        //身份证有效期是否长期
        if ([response[@"idCardDueDate"] isEqual:@"9999-12-31"]) {
            _idCardIsLongtime = YES;
            _idCardDateIsLongtimeImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
        } else {
            _idCardIsLongtime = NO;
            _idCardDateIsLongtimeImageView.image = image(@"gcy_img_home_business_nomal");
        }
        
        if ([[NSString nullToString:CJStringWithFormat(@"%@", response[@"isShare"])] isEqual:@"1"]) {
            _clearingImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
            _isClearing = YES;
            _cleanRatioTF.text = 0;
            _cleanRatioTF.enabled = NO;
            _cleanRatioView.hidden = NO;
            _cleanRatioTF.text = [NSString nullToString:CJStringWithFormat(@"%@", response[@"shareRatio"])];
            
        } else {
            _clearingImageView.image = image(@"gcy_img_home_business_nomal");
            _isClearing = NO;
            
        }
        
        //表单数据
        _cheDuiMingChengTF.text = [NSString nullToString:CJStringWithFormat(@"%@", response[@"linkMan"])];
        _phoneTF.text = [NSString nullToString:CJStringWithFormat(@"%@", response[@"phone"])];
        _lianXiRenTF.text = [NSString nullToString:CJStringWithFormat(@"%@", response[@"name"])];
        _tongXunDiZhiTF.text = [NSString nullToString:CJStringWithFormat(@"%@%@%@", response[@"provinceName"],response[@"cityName"],response[@"countyName"])];
        _detailAddressTF.text = [NSString nullToString:CJStringWithFormat(@"%@", response[@"homeAddress"])];
        _sheHuiTongYiXinYongDaiMaTF.text = [NSString nullToString:CJStringWithFormat(@"%@", response[@"businessLicenseNumber"])];
        _faRenTF.text = [NSString nullToString:CJStringWithFormat(@"%@", response[@"legalPerson"])];
        _idCardNumTF.text = [NSString nullToString:CJStringWithFormat(@"%@", response[@"identificationNumber"])];
        _idCardDueDateTF.text = [NSString nullToString:CJStringWithFormat(@"%@", response[@"idCardDueDate"])];//身份证有效期
        _lastIdardDueDate = [NSString nullToString:CJStringWithFormat(@"%@", response[@"idCardDueDate"])];
        _daoLuYunShuJingYingXuKeZhengTF.text = [NSString nullToString:CJStringWithFormat(@"%@", response[@"roadPermitNumber"])];
        _gongZuoDanWeiTF.text = [NSString nullToString:CJStringWithFormat(@"%@", response[@"workCompany"])];
        _beiZhuTF.text = [NSString nullToString:CJStringWithFormat(@"%@", response[@"remark"])];
        
        _provinceCode = [NSString nullToString:CJStringWithFormat(@"%@", response[@"provinceCode"])];
        _cityCode = [NSString nullToString:CJStringWithFormat(@"%@", response[@"cityCode"])];
        _countyCode = [NSString nullToString:CJStringWithFormat(@"%@", response[@"countyCode"])];
                
        //照片区域
        _identificationImg = [NSString nullToString: response[@"identificationImg"]];
        _identificationBackImg = [NSString nullToString: response[@"identificationBackImg"]];
        _businessLicenseImg = [NSString nullToString: response[@"businessLicenseImg"]];
        _roadPermitNumberImg = [NSString nullToString: response[@"roadPermitNumberImg"]];
        _safeDutyInsureImg = [NSString nullToString: response[@"safeDutyInsureImg"]];
        
        if ([DCSpeedy isBlankString:_identificationImg] == NO) {
            _identificationBtn.text = @"身份证人像面照片已上传";
            _identificationBtn.textColor = Dark_TextColor;
        }
        if ([DCSpeedy isBlankString:_identificationBackImg] == NO) {
            _identificationBackBtn.text = @"身份证国徽面照片已上传";
            _identificationBackBtn.textColor = Dark_TextColor;
        }
        if ([DCSpeedy isBlankString:_businessLicenseImg] == NO) {
            _businessLicenseImgBtn.text = @"统一社会信用代码照片已上传";
            _businessLicenseImgBtn.textColor = Dark_TextColor;
        }
        if ([DCSpeedy isBlankString:_roadPermitNumberImg] == NO) {
            _roadPermitNumberImgBtn.text = @"道路运输经营许可证照片已上传";
            _roadPermitNumberImgBtn.textColor = Dark_TextColor;
        }
        if ([DCSpeedy isBlankString:_safeDutyInsureImg] == NO) {
            _safeDutyInsureImgBtn.text = @"安全责任险照片已上传";
            _safeDutyInsureImgBtn.textColor = Dark_TextColor;
        }
        
#pragma mark - 证件是否过期判断(车队认证涉及1种证件)
        //身份证是否到期
        if (response[@"idCardDueDate"] != NULL) {
            
            NSInteger delta = [DCSpeedy calculateTimeDifference:response[@"idCardDueDate"]];

            if (delta<=30) {
                _idCardDueDateRemindLabel.hidden = NO;
                _identificationBtn.textColor = Red_Color;
                _identificationBackBtn.textColor = Red_Color;
                _idCardDueDateTF.textColor = Red_Color;
            } else {
                _idCardDueDateRemindLabel.hidden = YES;
            }
        }
        
        if ([DCSpeedy isBlankArr:response[@"overDueType"]] == NO) {
            NSArray *overDueArr = response[@"overDueType"];
            [overDueArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if ([obj containsString:@"road"]) {
                    //道路运输证
                    _roadPermitNumberImgBtn.textColor = Red_Color;
                }
            }];
        }
        
    } failure:^(NSInteger code, NSString *msg) {
        
    }];
}

#pragma mark - 保存
- (void)btnSaveEvent {
    WEAKSELF
    GeneralPopUp *generalPopUp = [[GeneralPopUp alloc] initWithFrame:CGRectMake(0, 0, ScreenW-100, 240)];
    cut(generalPopUp, 5);
    generalPopUp.backgroundColor = [UIColor whiteColor];
    generalPopUp.mainTitle = @"提示";
    generalPopUp.subTitle = @"请确认提交认证信息？";
    generalPopUp.handleBtnTitleArray = @[@"取消", @"确定"];
    [[GlobalPopUpTool sharedInstance] popUpWithView:generalPopUp withViewController:self withAnimation:YES withCanTapBgCancel:YES];
    generalPopUp.btnActionResultBlock = ^(BOOL isConfirm, NSString * _Nonnull title, NSInteger index) {
        [[GlobalPopUpTool sharedInstance] removePopUpView];
        if (isConfirm) {
            [weakSelf checkout];
        }
    };
    
}

/// 数据校验
- (void)checkout {
    if ([DCSpeedy isBlankDictionary:_dynamicFieldDic] == NO) {
        
        if ([_dynamicFieldDic[@"identificationImg"] integerValue] == 1 && _dynamicFieldDic[@"identificationImg"] != NULL) {
            if ([DCSpeedy isBlankString:_identificationImg]) {
                [XSInfoView showInfo:@"请上传身份证人像面照片" onView:self.view];
                return;
            }
        }
        if ([_dynamicFieldDic[@"identificationBackImg"] integerValue] == 1 && _dynamicFieldDic[@"identificationBackImg"] != NULL) {
            if ([DCSpeedy isBlankString:_identificationBackImg]) {
                [XSInfoView showInfo:@"请上传身份证国徽面照片" onView:self.view];
                return;
            }
        }
        if ([_dynamicFieldDic[@"businessLicenseImg"] integerValue] == 1 && _dynamicFieldDic[@"businessLicenseImg"] != NULL) {
            if ([DCSpeedy isBlankString:_businessLicenseImg]) {
                [XSInfoView showInfo:@"请上传统一社会信用代码照片" onView:self.view];
                return;
            }
        }
        if ([_dynamicFieldDic[@"roadPermitNumberImg"] integerValue] == 1 && _dynamicFieldDic[@"roadPermitNumberImg"] != NULL) {
            if ([DCSpeedy isBlankString:_roadPermitNumberImg]) {
                [XSInfoView showInfo:@"请上传道路运输经营许可证照片" onView:self.view];
                return;
            }
        }
        if ([_dynamicFieldDic[@"safeDutyInsureImg"] integerValue] == 1 && _dynamicFieldDic[@"safeDutyInsureImg"] != NULL) {
            if ([DCSpeedy isBlankString:_safeDutyInsureImg]) {
                [XSInfoView showInfo:@"请上传安全责任险照片" onView:self.view];
                return;
            }
        }
        if ([_dynamicFieldDic[@"linkMan"] integerValue] == 1 && _dynamicFieldDic[@"linkMan"] != NULL) {
            if ([DCSpeedy isBlankString:_cheDuiMingChengTF.text]) {
                [XSInfoView showInfo:@"请填写车队名称" onView:self.view];
                return;
            }
        }
        if ([_dynamicFieldDic[@"phone"] integerValue] == 1 && _dynamicFieldDic[@"phone"] != NULL) {
            if ([DCSpeedy isBlankString:_phoneTF.text]) {
                [XSInfoView showInfo:@"请填写联系方式" onView:self.view];
                return;
            }
        }
        if ([_dynamicFieldDic[@"name"] integerValue] == 1 && _dynamicFieldDic[@"name"] != NULL) {
            if ([DCSpeedy isBlankString:_lianXiRenTF.text]) {
                [XSInfoView showInfo:@"请填写联系人" onView:self.view];
                return;
            }
        }
        if ([_dynamicFieldDic[@"areaList"] integerValue] == 1 && _dynamicFieldDic[@"areaList"] != NULL) {
            if ([DCSpeedy isBlankString:_provinceCode]) {
                [XSInfoView showInfo:@"请选择通信地址" onView:self.view];
                return;
            }
        }
        if ([_dynamicFieldDic[@"homeAddress"] integerValue] == 1 && _dynamicFieldDic[@"homeAddress"] != NULL) {
            if ([DCSpeedy isBlankString:_detailAddressTF.text]) {
                [XSInfoView showInfo:@"请填写详细地址" onView:self.view];
                return;
            }
        }
        if ([_dynamicFieldDic[@"businessLicenseNumber"] integerValue] == 1 && _dynamicFieldDic[@"businessLicenseNumber"] != NULL) {
            if ([DCSpeedy isBlankString:_sheHuiTongYiXinYongDaiMaTF.text]) {
                [XSInfoView showInfo:@"请填写统一社会信用代码" onView:self.view];
                return;
            }
        }
        if ([_dynamicFieldDic[@"legalPerson"] integerValue] == 1 && _dynamicFieldDic[@"legalPerson"] != NULL) {
            if ([DCSpeedy isBlankString:_faRenTF.text]) {
                [XSInfoView showInfo:@"请填写法人姓名" onView:self.view];
                return;
            }
        }
        if ([_dynamicFieldDic[@"identificationNumber"] integerValue] == 1 && _dynamicFieldDic[@"identificationNumber"] != NULL) {
            if ([DCSpeedy isBlankString:_idCardNumTF.text]) {
                [XSInfoView showInfo:@"请填写身份证号码" onView:self.view];
                return;
            }
            if ([CYCheckRegular cy_checkUserIcyard:_idCardNumTF.text] == NO) {
                [XSInfoView showInfo:@"请填写正确的身份证号" onView:self.view];
                return;
            }
        }
        if ([_dynamicFieldDic[@"roadPermitNumber"] integerValue] == 1 && _dynamicFieldDic[@"roadPermitNumber"] != NULL) {
            if ([DCSpeedy isBlankString:_daoLuYunShuJingYingXuKeZhengTF.text]) {
                [XSInfoView showInfo:@"请填写道路运输经营许可证号" onView:self.view];
                return;
            }
        }
        if ([_dynamicFieldDic[@"workCompany"] integerValue] == 1 && _dynamicFieldDic[@"workCompany"] != NULL) {
            if ([DCSpeedy isBlankString:_gongZuoDanWeiTF.text]) {
                [XSInfoView showInfo:@"请填写工作单位" onView:self.view];
                return;
            }
        }
        
        if ([_dynamicFieldDic[@"idCardDueDate"] integerValue] == 1 && _dynamicFieldDic[@"idCardDueDate"] != NULL) {
            if ([DCSpeedy isBlankString:_idCardDueDateTF.text]) {
                [XSInfoView showInfo:@"请选择身份证到期日期" onView:self.view];
                return;
            }
        }
        
        if (_isClearing && [DCSpeedy isBlankString:_cleanRatioTF.text]) {
            [XSInfoView showInfo:@"请填写清分比率" onView:self.view];
            return;
        } else {
            if ([_cleanRatioTF.text integerValue] > 100) {
                [XSInfoView showInfo:@"清分比率不能大于100%,请重新输入" onView:self.view];
                _cleanRatioTF.text = @"";
                return;
            }
        }
        
    } else {

#pragma mark - 必填校验及格式验证
//        if ([DCSpeedy isBlankString:_cheDuiMingChengTF.text] || [DCSpeedy isBlankString:_idCardNumTF.text] || [DCSpeedy isBlankString:_phoneTF.text] || [DCSpeedy isBlankString:_lianXiRenTF.text] || [DCSpeedy isBlankString:_detailAddressTF.text] || [DCSpeedy isBlankString:_provinceCode] || [DCSpeedy isBlankString:_sheHuiTongYiXinYongDaiMaTF.text] || [DCSpeedy isBlankString:_faRenTF.text] || [DCSpeedy isBlankString:_gongZuoDanWeiTF.text] || [DCSpeedy isBlankString:_identificationImg] || [DCSpeedy isBlankString:_identificationBackImg] || [DCSpeedy isBlankString:_businessLicenseImg]) {
//            [XSInfoView showInfo:@"必填信息不能为空" onView:self.view];
//            return;
//        }
        
//        if ([CYCheckRegular cy_checkUserIcyard:_idCardNumTF.text] == NO) {
//            [XSInfoView showInfo:@"请填写正确的身份证号" onView:self.view];
//            return;
//        }
        
//        if (_sheHuiTongYiXinYongDaiMaTF.text.length == 10 || _sheHuiTongYiXinYongDaiMaTF.text.length == 18) {
//
//        } else {
//            [XSInfoView showInfo:@"统一信用代码必须为10位或18位" onView:self.view];
//            return;
//        }
        
//        if (_isClearing == NO) {
//            if ([DCSpeedy isBlankString:_roadPermitNumberImg]) {
//                [XSInfoView showInfo:@"请上传道路运输经营许可证照" onView:self.view];
//                return;
//            }
//            if ([DCSpeedy isBlankString:_daoLuYunShuJingYingXuKeZhengTF.text]) {
//                [XSInfoView showInfo:@"请填写道路运输经营许可证号" onView:self.view];
//                return;
//            }
//            if (_daoLuYunShuJingYingXuKeZhengTF.text.length != 12) {
//                [XSInfoView showInfo:@"道路运输经营许可证号必须为12位" onView:self.view];
//                return;
//            }
//        }
//
//        if (_isClearing && [DCSpeedy isBlankString:_cleanRatioTF.text]) {
//            [XSInfoView showInfo:@"请填写清分比率" onView:self.view];
//            return;
//        } else {
//            if ([_cleanRatioTF.text integerValue] > 100) {
//                [XSInfoView showInfo:@"清分比率不能大于100%,请重新输入" onView:self.view];
//                _cleanRatioTF.text = @"";
//                return;
//            }
//        }
        
    }
    
    
    [self carTeamInfoSubmitRequest];
    
//    if ([[UserDefaultUtil valueForKey:Login_Branch][@"taxPlatform"] integerValue] == 2 && [[UserDefaultUtil valueForKey:Login_Branch][@"isLiveness"] integerValue] == 0) {
//
//        //使用拍照方式人证核验
//        [HTTPManager getNetworkRequest:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-basic-api",[ReAddressDynamic shared].baseUrl], DRIVER_VERIFYIDENTITYONOFF) withParameter:@{@"branchCode": [UserDefaultUtil valueForKey:BranchCode], @"token":[UserDefaultUtil valueForKey:USER_TOKEN],} withVC:self netName:@"是否开启身份验证" success:^(id response, NSString *msg) {
//            if ([response[@"toVerifyIdentity"] integerValue] == 1) {
//
//                TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 columnNumber:4 delegate:nil pushPhotoPickerVc:YES];
//                [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
//
//                    [HTTPManager postUploadFiles:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-tps-api",[ReAddressDynamic shared].baseUrl], FILE_UPLOAD) file:@[[photos firstObject]] fileName:@"file" withVC:self netName:@"文件上传" success:^(id response, NSString *msg) {
//
//                        NSDictionary *parmas = @{
//                            @"peopleImg": response[@"data"],
//                            @"branchCode": [UserDefaultUtil valueForKey:BranchCode],
//                            @"token":[UserDefaultUtil valueForKey:USER_TOKEN],
//                        };
//                        [HTTPManager getNetworkRequest:CJStringWithFormat(@"%@/ntocc-basic-api/driver/faceVerify", BasicDomainURL) withParameter:parmas withVC:self netName:@"身份验证" success:^(id response, NSString *msg) {
//
//                            if ([response[@"pass"] integerValue] == 1) {
//
//                                [self carTeamInfoSubmitRequest];
//
//                            } else {
//
//                                [XSInfoView showInfo:response[@"msg"] onView:self.view];
//                            }
//
//                        } failure:^(NSInteger code, NSString *msg) {
//
//                        }];
//
//                    } failure:^(NSInteger code, NSString *msg) {
//
//                    }];
//
//                }];
//                imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen;
//                [self presentViewController:imagePickerVc animated:YES completion:nil];
//
//            } else {
//
//                [self carTeamInfoSubmitRequest];
//            }
//
//        } failure:^(NSInteger code, NSString *msg) {
//
//        }];
//
//
//    } else {
//
//        [HTTPManager getNetworkRequest:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-basic-api",[ReAddressDynamic shared].baseUrl], DRIVER_VERIFYIDENTITYONOFF) withParameter:@{@"branchCode": [UserDefaultUtil valueForKey:BranchCode], @"token":[UserDefaultUtil valueForKey:USER_TOKEN],} withVC:self netName:@"是否开启身份验证" success:^(id response, NSString *msg) {
//            if ([response[@"toVerifyIdentity"] integerValue] == 1) {
//                //开启了
//                if (![[FaceSDKManager sharedInstance] canWork]) {
//                    NSString* licensePath = [[NSBundle mainBundle] pathForResource:FACE_LICENSE_NAME ofType:FACE_LICENSE_SUFFIX];
//                    [[FaceSDKManager sharedInstance] setLicenseID:FACE_LICENSE_ID andLocalLicenceFile:licensePath andRemoteAuthorize:YES];
//                }
//                [self faceLiveness];
//
//            } else {
//
//                [self carTeamInfoSubmitRequest];
//            }
//
//        } failure:^(NSInteger code, NSString *msg) {
//
//        }];
//
//    }
}

#ifdef isOpenBaiDuFaceSDK
//人脸认证
- (void)faceLiveness {
    BDFaceLivenessViewController* lvc = [[BDFaceLivenessViewController alloc] init];
    BDFaceLivingConfigModel* model = [BDFaceLivingConfigModel sharedInstance];
    [lvc livenesswithList:model.liveActionArray order:model.isByOrder numberOfLiveness:model.numOfLiveness];
    UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:lvc];
    navi.navigationBarHidden = true;
    navi.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:navi animated:YES completion:nil];
}
#endif


#pragma mark - 车队认证信息提交
- (void)carTeamInfoSubmitRequest {
    WEAKSELF
    NSDictionary *parmas = @{
        
        @"linkMan": [_cheDuiMingChengTF.text stringByReplacingOccurrencesOfString:@" " withString:@""],//车队名称
        @"identificationNumber": _idCardNumTF.text,//身份证
        @"idCardDueDate": _idCardDueDateTF.text,//身份证有效期
        @"phone": _phoneTF.text,
        @"name": _lianXiRenTF.text,//联系人
        @"provinceCode": _provinceCode,
        @"cityCode": _cityCode,
        @"countyCode": _countyCode,
        @"homeAddress": _detailAddressTF.text,//详细地址
        @"businessLicenseNumber": _sheHuiTongYiXinYongDaiMaTF.text,//营业执照号
        @"legalPerson": _faRenTF.text,//法人代表名称
        @"roadPermitNumber": _daoLuYunShuJingYingXuKeZhengTF.text,//道路经营许可证
        @"workCompany": _gongZuoDanWeiTF.text,//工作单位
//        @"sex": _sex,//性别
//        @"remark": _beiZhuTF.text,//备注
        @"allowDriverReceive": _allowDriverReceive,
        @"isShare": _isClearing == YES ? @"1" : @"0",//是否清分
        @"shareRatio": _cleanRatioTF.text,//清分比率
        @"identificationImg": _identificationImg,//身份证正面照
        @"identificationBackImg": _identificationBackImg,//身份证反面照
        @"businessLicenseImg": _businessLicenseImg,//营业执照照片
        @"roadPermitNumberImg": _roadPermitNumberImg,//道路经营许可证
        @"safeDutyInsureImg": _safeDutyInsureImg,//安全责任险照片
        
        @"partyCode":[UserDefaultUtil valueForKey:DriverPartyCode],
        @"token":[UserDefaultUtil valueForKey:USER_TOKEN],
        
    };
    
    [HTTPManager putNetworkRequest:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-basic-api",[ReAddressDynamic shared].baseUrl], DRIVER_UPDATEINFO) withParameter:parmas withVC:self netName:@"车队信息认证" success:^(id response, NSString *msg) {
        
        [XSInfoView showInfo:msg onView:weakSelf.view];
        
        [KNotificationCenter postNotificationName:LOGIN_SUCCESS object:nil];
        [KNotificationCenter postNotificationName:DUE_ALERT object:nil];
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void){
            [weakSelf.navigationController popViewControllerAnimated:YES];
        });
        
    } failure:^(NSInteger code, NSString *msg) {
        
    }];
}

#pragma mark - 活体检测结果通知
- (void)faceIdentifyCompleted:(NSNotification *)notifi {
    
    NSDictionary *parmas = @{
        @"imageUrl": notifi.object,
        @"identificationImg": _identificationImg,
        @"livenessVerify": @"1",
        @"branchCode": [UserDefaultUtil valueForKey:BranchCode],
        @"token":[UserDefaultUtil valueForKey:USER_TOKEN],
    };
    [HTTPManager getNetworkRequest:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-basic-api",[ReAddressDynamic shared].baseUrl], DRIVER_VERIFYIDENTITY) withParameter:parmas withVC:self netName:@"身份验证" success:^(id response, NSString *msg) {
        
        if ([response[@"pass"] integerValue] == 1) {
            
            [self carTeamInfoSubmitRequest];
            
        } else {
            
            [XSInfoView showInfo:response[@"msg"] onView:self.view];
            
        }
        
    } failure:^(NSInteger code, NSString *msg) {
        
    }];
    
}

#pragma mark -- DeliveredImageUrlDelegate
- (void)getImageUrlSting:(NSString *)string andImageType:(NSInteger)type {
    
   
    NSString *ocrType = @"";
    
    if (type == 2) {
        //身份证
        ocrType = @"ocrIdidentityCardFront";
        _identificationImg = string;
        _identificationBtn.text = @"身份证人像面照片已上传";
        _identificationBtn.textColor = Dark_TextColor;
        
    } else if (type == 3) {
        ocrType = @"ocrIdidentityCardFrontBack";
        _identificationBackImg = string;
        _identificationBackBtn.text = @"身份证国徽面照片已上传";
        _identificationBackBtn.textColor = Dark_TextColor;
        
    } else if (type == 10) {
        //社会统一信用代码
        ocrType = @"ocrBusinessLicense";
        _businessLicenseImg = string;
        _businessLicenseImgBtn.text = @"统一社会信用代码照片已上传";
        _businessLicenseImgBtn.textColor = Dark_TextColor;
        
    } else if (type == 13) {
        //道路运输经营许可证
        ocrType = @"ocrRoadPermitNumber";
        _roadPermitNumberImg = string;
        _roadPermitNumberImgBtn.text = @"道路运输经营许可证照片已上传";
        _roadPermitNumberImgBtn.textColor = Dark_TextColor;
        
    } else if (type == 15) {
        _safeDutyInsureImg = string;
        _safeDutyInsureImgBtn.text = @"安全责任险照片已上传";
        _safeDutyInsureImgBtn.textColor = Dark_TextColor;
        
    }
    
#pragma mark - OCR识别
    if (type == 2 || type == 3 || type == 10 || type == 13) {
        
        NSDictionary *parmas = @{
            @"image": string,
            @"ocrType": ocrType,
            @"token":[UserDefaultUtil valueForKey:USER_TOKEN],
        };
        
        [HTTPManager getNetworkRequest:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-tps-api",[ReAddressDynamic shared].baseUrl], NTOCC_OCRCARD) withParameter:parmas withVC:self netName:@"OCR识别" success:^(id response, NSString *msg) {
            
            [XSInfoView showInfo:msg onView:self.view];
            
            if (type == 2) {
                
                //身份证
                if ([DCSpeedy isBlankString:response[@"name"]] == NO) {
                    //法人
                    _faRenTF.text = response[@"name"];
                }
                if ([DCSpeedy isBlankString:response[@"identity"]] == NO) {
                    _idCardNumTF.text = response[@"identity"];
                }
                //10-19修改 车队长不取身份证详细地址相关字段 暂时注释
                /*
                if ([DCSpeedy isBlankString:response[@"provinceCode"]] == NO) {
                    _provinceCode = response[@"provinceCode"];
                }
                if ([DCSpeedy isBlankString:response[@"cityCode"]] == NO) {
                    _cityCode = response[@"cityCode"];
                }
                if ([DCSpeedy isBlankString:response[@"countyCode"]] == NO) {
                    _countyCode = response[@"countyCode"];
                }
                
                if ([DCSpeedy isBlankString:response[@"provinceName"]] == NO && [DCSpeedy isBlankString:response[@"cityName"]] == NO && [DCSpeedy isBlankString:response[@"countyName"]] == NO) {
                    NSString *address = CJStringWithFormat(@"%@%@%@",response[@"provinceName"],response[@"cityName"],response[@"countyName"]);
                    _tongXunDiZhiTF.text = address;
                }
                 
                if ([DCSpeedy isBlankString:response[@"address"]] == NO) {
                    _detailAddressTF.text = response[@"address"];
                }
                 */
                
            } else if (type == 3) {
                //身份证反面
//                if ([DCSpeedy isBlankString:response[@"expiryDate"]] == NO) {
//                    _idCardDueDateTF.text = [DCSpeedy ocrDateFormatter:response[@"expiryDate"]];
//                }
                
                if ([DCSpeedy isBlankString:response[@"expiryDate"]] == NO && ([response[@"expiryDate"] isEqual:@"长期"] || [response[@"expiryDate"] isEqual:@"9999-12-31"])) {
                    _idCardIsLongtime = YES;
                    _idCardDateIsLongtimeImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
                    _idCardDueDateTF.text = @"9999-12-31";
                } else {
                    _idCardIsLongtime = NO;
                    _idCardDateIsLongtimeImageView.image = image(@"gcy_img_home_business_nomal");
                    _idCardDueDateTF.text = [DCSpeedy ocrDateFormatter:response[@"expiryDate"]];
                }
                
            } else if (type == 10) {
                //社会统一信用代码
                // 公司名称
                if ([DCSpeedy isBlankString:response[@"companyName"]] == NO) {
                    _gongZuoDanWeiTF.text = response[@"companyName"];
                }
                
                //社会信用代码
                if ([DCSpeedy isBlankString:response[@"creditNum"]] == NO) {
                    _sheHuiTongYiXinYongDaiMaTF.text = response[@"creditNum"];
                }
                
                //法人代表名称
//                if ([DCSpeedy isBlankString:response[@"legalPerson"]] == NO) {
//                    _faRenTF.text = response[@"legalPerson"];
//                }
                
            } else if (type == 13) {
                //道路经营许可证
                if ([DCSpeedy isBlankString:response[@"hao"]] == NO) {
                    _daoLuYunShuJingYingXuKeZhengTF.text = [NSString nullToString:CJStringWithFormat(@"%@", response[@"hao"])];
                }
                
            }
            
        } failure:^(NSInteger code, NSString *msg) {
            
        }];
        
    }
    
}
- (void)identificationBtnEvent {
    //身份证正面
    self.uploadImgVC.imageType = 2;
    self.uploadImgVC.imageNetUrl = _identificationImg;
    [self.navigationController pushViewController:self.uploadImgVC animated:YES];
}
- (void)identificationBackBtnEvent {
    //身份证反面
    self.uploadImgVC.imageType = 3;
    self.uploadImgVC.imageNetUrl = _identificationBackImg;
    [self.navigationController pushViewController:self.uploadImgVC animated:YES];
}
- (void)businessLicenseImgBtnEvent {
    //统一社会信用代码照
    self.uploadImgVC.imageType = 10;
    self.uploadImgVC.imageNetUrl = _businessLicenseImg;
    [self.navigationController pushViewController:self.uploadImgVC animated:YES];
}
- (void)roadPermitNumberImgBtnEvent {
    //道路运输经营许可证照
    self.uploadImgVC.imageType = 13;
    self.uploadImgVC.imageNetUrl = _roadPermitNumberImg;
    [self.navigationController pushViewController:self.uploadImgVC animated:YES];
}
- (void)safeDutyInsureImgBtnEvent {
    //安全责任险照
    self.uploadImgVC.imageType = 15;
    self.uploadImgVC.imageNetUrl = _safeDutyInsureImg;
    [self.navigationController pushViewController:self.uploadImgVC animated:YES];
}
///通讯地址
- (void)provincesCityCountyChooseEvent {
    //通讯地址
    [[CYCityChooseView shared] show];
    [CYCityChooseView shared].pageShowFlag = 1;
    [CYCityChooseView shared].delegate = self;
}
///身份证到期日期
- (void)idCardDueDateEvent{
    BRDatePickerView *datePickerView = [[BRDatePickerView alloc]initWithPickerMode:BRDatePickerModeYMD];
    datePickerView.title = @"身份证到期日期";
    datePickerView.isAutoSelect = NO;
    datePickerView.showToday = NO; // 是否显示“今天”
    datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {
        _idCardDueDateTF.text = selectValue;
        _lastIdardDueDate = selectValue;
    };
    [datePickerView show:self];
}
- (void)sexManEvent {
    _manImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
    _womenImageView.image = image(@"gcy_img_home_business_nomal");
    _sex = @"1";
}
- (void)sexWomanEvent {
    _manImageView.image = image(@"gcy_img_home_business_nomal");
    _womenImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
    _sex = @"2";
}
- (void)notAllowDriverReceiveEvent {
    _allowDriverReceivImageView.image = image(@"gcy_img_home_business_nomal");
    _notAllowDriverReceivView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
    _allowDriverReceive = @"1";
}
- (void)allowDriverReceiveEvent {
    _notAllowDriverReceivView.image = image(@"gcy_img_home_business_nomal");
    _allowDriverReceivImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
    _allowDriverReceive = @"0";
}
///是否清分
- (void)clearingBtnEvent {
    if (_isClearing) {
        //不清分
        _clearingImageView.image = image(@"gcy_img_home_business_nomal");
        _cleanRatioView.hidden = YES;
//        _dlysjyxkeAsterisk.hidden = NO;
//        _dlysjyxkeImgAsterisk.hidden = NO;
    } else {
        //清分
        _cleanRatioTF.text = 0;
        _cleanRatioTF.enabled = NO;
        _clearingImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
        _cleanRatioView.hidden = NO;
//        _dlysjyxkeAsterisk.hidden = YES;
//        _dlysjyxkeImgAsterisk.hidden = YES;
    }
    _isClearing = !_isClearing;
}

- (void)idCardDateIsLongtimeEvent {
    if (_idCardIsLongtime) {
        //不是长期
        _idCardDateIsLongtimeImageView.image = image(@"gcy_img_home_business_nomal");
//        _idCardDueDateTF.text = [DCSpeedy generalGetCurrentDate:@"YYYY-MM-dd"];
        _idCardDueDateTF.text = _lastIdardDueDate;

    } else {
        //长期
        _idCardDateIsLongtimeImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
        _idCardDueDateTF.text = @"9999-12-31";
    }
    _idCardIsLongtime = !_idCardIsLongtime;
}

#pragma mark - CYChooseRegionDelegate
- (void)getAllInfoProvinceCode:(NSString *)provinceCode provinceName:(NSString *)provinceName cityCode:(NSString *)cityCode cityName:(NSString *)cityName countyCode:(NSString *)countyCode countyName:(NSString *)countyName {
    
    if ([DCSpeedy isBlankString:countyCode] == YES) {
        [XSInfoView showInfo:@"通信地址请精确到区/县" onView:self.view];
        
        [[CYCityChooseView shared] show];
        [CYCityChooseView shared].pageShowFlag = 1;
        [CYCityChooseView shared].delegate = self;
        
        return;
    }
    
    NSString *address = CJStringWithFormat(@"%@%@%@",provinceName,cityName,countyName);
    _tongXunDiZhiTF.text = address;
    
    _provinceCode = provinceCode;
    _cityCode = cityCode;
    _countyCode = countyCode;
}

- (ImageUploadViewController *)uploadImgVC {
    if (!_uploadImgVC) {
        _uploadImgVC = [[ImageUploadViewController alloc] init];
        _uploadImgVC.delegate = self;
    }
    return _uploadImgVC;
}

#pragma mark - 表单验证规范
- (void)formValidationSetup {
    
    /*车队名称*/
    _cheDuiMingChengTF.textFieldType = CJTextFieldStringTypeNone;
    _cheDuiMingChengTF.maxLength = 20;
    
    /*联系电话*/
    _phoneTF.textFieldType = CJTextFieldStringTypeNumber;
    _phoneTF.keyboardType = UIKeyboardTypeNumberPad;
    _phoneTF.maxLength = 11;
    
    /*联系人*/
    _lianXiRenTF.textFieldType = CJTextFieldStringTypeNone;
    _lianXiRenTF.maxLength = 20;
    
    /*详细地址*/
    _detailAddressTF.textFieldType = CJTextFieldStringTypeNone;
    _detailAddressTF.maxLength = 128;
    
    /*信用代码*/
    _sheHuiTongYiXinYongDaiMaTF.textFieldType = CJTextFieldStringTypePassword;
//    _sheHuiTongYiXinYongDaiMaTF.keyboardType = UIKeyboardTypeNumberPad;
    _sheHuiTongYiXinYongDaiMaTF.maxLength = 128;
    
    /*法人*/
    _faRenTF.textFieldType = CJTextFieldStringTypeNone;
    _faRenTF.maxLength = 6;
    
    /*身份证号*/
    _idCardNumTF.textFieldType = CJTextFieldStringTypeNone;
    _idCardNumTF.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    _idCardNumTF.maxLength = 18;
    
    /*道路运输经营许可证*/
    _daoLuYunShuJingYingXuKeZhengTF.textFieldType = CJTextFieldStringTypeNumber;
    _daoLuYunShuJingYingXuKeZhengTF.keyboardType = UIKeyboardTypeNumberPad;
    _daoLuYunShuJingYingXuKeZhengTF.maxLength = 128;
    
    /*工作单位*/
    _gongZuoDanWeiTF.textFieldType = CJTextFieldStringTypeNone;
    _gongZuoDanWeiTF.maxLength = 128;
    
    /*备注*/
    _beiZhuTF.textFieldType = CJTextFieldStringTypeNone;
    _beiZhuTF.maxLength = 30;
    
    /*清分比率*/
    _cleanRatioTF.textFieldType = CJTextFieldStringTypeNumber;
    _cleanRatioTF.keyboardType = UIKeyboardTypeNumberPad;
    _cleanRatioTF.maxLength = 3;
}

#pragma  mark - textField delegate
//- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
//{
//    NSLog(@"1111 === %@",_cleanRatioTF.text);
//    if (_cleanRatioTF == textField) {
//        NSLog(@"222 === %@",_cleanRatioTF.text);//输入文字时 一直监听
//        if ([_cleanRatioTF.text integerValue] > 100) {
//            [XSInfoView showInfo:@"清分比率不能大于100%" onView:self.view];
//            _cleanRatioTF.text = @"";
//             return NO;
//        } else {
//            return YES;
//        }
//    }
//    return YES;
//}

@end
